{{>licenseInfo}}
{{=< >=}}
import {ApiClient} from '../ApiClient.js';
<#imports>import {<import>} from '../<#modelPackage><&modelPackage>/</modelPackage><import>.js';
</imports>
import {SuperagentRateLimiter} from '../../../helper/SuperagentRateLimiter.mjs';
import {DefaultRateLimitFetcher} from '../../../helper/DefaultRateLimitFetcher.mjs';

<#emitJSDoc>/**
* <baseName> service.
* @module <#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><classname>
* @version <projectVersion>
*/</emitJSDoc>
export class <classname> {

    // Private member stores the default rate limiters
    #defaultRateLimiterMap;

    <#emitJSDoc>/**
    * Constructs a new <&classname>. <#description>
    * <description></description>
    * @alias module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><apiPackage>/</apiPackage><classname>
    * @class
    * @param {ApiClient} [apiClient] Optional API client implementation to use,
    * default to {@link ApiClient#instance} if unspecified.
    */</emitJSDoc>
    constructor(apiClient) {
        this.apiClient = apiClient || ApiClient.instance;
        this.initializeDefaultRateLimiterMap();
    }

    /**
     * Initialize rate limiters for API operations
     */
    initializeDefaultRateLimiterMap() {
        this.#defaultRateLimiterMap = new Map()
        const defaultRateLimitFetcher = new DefaultRateLimitFetcher();
        const operations = [
<#operations><#operation>            '<classname>-<operationId>',
</operation></operations>        ];

        for (const operation of operations) {
            const config = defaultRateLimitFetcher.getLimit(operation);
            this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config));
        }
    }

    /**
     * Get rate limiter for a specific operation
     * @param {String} operation name
     */
    getRateLimiter(operation) {
        return this.#defaultRateLimiterMap.get(operation);
    }

<#operations><#operation><#emitJSDoc><^usePromises>
    /**
     * Callback function to receive the result of the <operationId> operation.
     * @callback module:<#invokerPackage><invokerPackage>/</invokerPackage><#apiPackage><apiPackage>/</apiPackage><classname>~<operationId>Callback
     * @param {String} error Error message, if any.
     * @param <#vendorExtensions.x-jsdoc-type>{<&vendorExtensions.x-jsdoc-type>} data The data returned by the service call.</vendorExtensions.x-jsdoc-type><^vendorExtensions.x-jsdoc-type>data This operation does not return a value.</vendorExtensions.x-jsdoc-type>
     * @param {String} response The complete HTTP response.
     */</usePromises>

    /**<#summary>
     * <summary></summary><#notes>
     * <notes></notes><#allParams><#required>
     * @param {<dataType>} <paramName> <description></required></allParams><#hasOptionalParams>
     * @param {Object} opts Optional parameters<#allParams><^required>
     * @param {<dataType>} opts.<paramName> <description><#defaultValue> (default to <.>)</defaultValue></required></allParams></hasOptionalParams><^usePromises>
     * @param {module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><&classname>~<operationId>Callback} callback The callback function, accepting three arguments: error, data, response<#returnType>
     * data is of type: {@link <&vendorExtensions.x-jsdoc-type>}</returnType></usePromises><#usePromises>
     * @return <#returnType>{Promise<={{ }}=><{{returnType}}>{{=< >=}}}</returnType><^returnType>{Promise<={{ }}=><void>{{=< >=}}}</returnType></usePromises>
     */
</emitJSDoc>    <operationId><#usePromises>WithHttpInfo</usePromises>(<vendorExtensions.x-codegen-arg-list><^usePromises><#hasParams>, </hasParams>callback</usePromises>) {<#hasOptionalParams>
      opts = opts || {};</hasOptionalParams>
      let postBody = <#bodyParam><#required><paramName></required><^required>opts['<paramName>']</required></bodyParam><^bodyParam>null</bodyParam>;
<#allParams><#required>
      // verify the required parameter '<paramName>' is set
      if (<paramName> === undefined || <paramName> === null) {
        throw new Error("Missing the required parameter '<paramName>' when calling <operationId>");
      }
</required></allParams>

      let pathParams = {<#pathParams>
        '<baseName>': <#required><paramName></required><^required>opts['<paramName>']</required><^-last>,</-last></pathParams>
      };
      let queryParams = {<#queryParams>
        '<baseName>': <#collectionFormat>this.apiClient.buildCollectionParam(<#required><paramName></required><^required>opts['<paramName>']</required>, '<collectionFormat>')</collectionFormat><^collectionFormat><#required><paramName></required><^required>opts['<paramName>']</required></collectionFormat><^-last>,</-last></queryParams>
      };
      let headerParams = {<#headerParams>
        '<baseName>': <#required><paramName></required><^required>opts['<paramName>']</required><^-last>,</-last></headerParams>
      };
      let formParams = {<#formParams>
        '<baseName>': <#collectionFormat>this.apiClient.buildCollectionParam(<#required><paramName></required><^required>opts['<paramName>']</required>, '<collectionFormat>')</collectionFormat><^collectionFormat><#required><paramName></required><^required>opts['<paramName>']</required></collectionFormat><^-last>,</-last></formParams>
      };

      let contentTypes = [<#consumes>'<& mediaType>'<^-last>, </-last></consumes>];
      let accepts = [<#produces>'<& mediaType>'<^-last>, </-last></produces>];
      let returnType = <#returnType><&returnType></returnType><^returnType>null</returnType>;

      return this.apiClient.callApi( '<classname>-<operationId>',
        '<&path>', '<httpMethod>',
        pathParams, queryParams, headerParams, formParams, postBody,
        contentTypes, accepts, returnType, this.getRateLimiter('<classname>-<operationId>')<^usePromises>, callback</usePromises>
      );
    }
<#usePromises>
    <#emitJSDoc>

    /**<#summary>
     * <summary></summary><#notes>
     * <notes></notes><#allParams><#required>
     * @param {<dataType>} <paramName> <description></required></allParams><#hasOptionalParams>
     * @param {Object} opts Optional parameters<#allParams><^required>
     * @param {<dataType>} opts.<paramName> <description><#defaultValue> (default to <.>)</defaultValue></required></allParams></hasOptionalParams><^usePromises>
     * @param {module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><&classname>~<operationId>Callback} callback The callback function, accepting three arguments: error, data, response<#returnType>
     * data is of type: {@link <&vendorExtensions.x-jsdoc-type>}</returnType></usePromises><#usePromises>
     * @return <#returnType>{Promise<={{ }}=><{{returnType}}>{{=< >=}}}</returnType><^returnType>{Promise<={{ }}=><void>{{=< >=}}}</returnType></usePromises>
     */
</emitJSDoc>    <operationId>(<vendorExtensions.x-codegen-arg-list>) {
      return this.<operationId>WithHttpInfo(<vendorExtensions.x-codegen-arg-list>)
        .then(function(response_and_data) {
          return response_and_data.data;
        });
    }
</usePromises>
</operation></operations>

}
<={{ }}=>
